package com.xbongbong.saas.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasAppEntity;
import com.xbongbong.paas.domain.entity.PaasCommentEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.enums.PlatFormEnum;
import com.xbongbong.paas.model.PaasAppModel;
import com.xbongbong.paas.model.PaasCommentModel;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.pojo.dto.LikeAddDTO;
import com.xbongbong.paas.pojo.dto.LikeAddOnCommentDTO;
import com.xbongbong.paas.pojo.dto.LikeListDTO;
import com.xbongbong.paas.pojo.vo.LikeListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.message.constant.CommunicatePushConstant;
import com.xbongbong.pro.message.constant.DistributorCommunicatePushConstant;
import com.xbongbong.pro.message.constant.WorkOrderPushConstant;
import com.xbongbong.pro.message.constant.WorkReportPushConstant;
import com.xbongbong.pro.message.enums.PushTypeEnum;
import com.xbongbong.pro.message.pojo.PushRefTypePojo;
import com.xbongbong.pro.message.pojo.dto.MessageRabbitMqDTO;
import com.xbongbong.pro.rabbitmq.producer.BaseProducer;
import com.xbongbong.saas.constant.ErrorMessageConstant;
import com.xbongbong.saas.domain.entity.LikeEntity;
import com.xbongbong.saas.enums.BusinessCommentEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.CustomerCommunicateEnum;
import com.xbongbong.saas.enums.business.DistributorCommunicateEnum;
import com.xbongbong.saas.help.SaasGetHelp;
import com.xbongbong.saas.model.LikeModel;
import com.xbongbong.saas.service.LikeService;
import com.xbongbong.saas.toolbox.help.FastJsonHelper;
import com.xbongbong.sys.domain.entity.UserEntity;
import com.xbongbong.sys.model.UserModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/2/27 19:44
 * @since v1.0
 */
@Service("likeService")
public class LikeServiceImpl implements LikeService {

    @Resource
    private LikeModel likeModel;
    @Resource
    private UserModel userModel;
    @Resource
    private SaasGetHelp saasGetHelp;
    @Resource
    private BaseProducer baseProducer;
    @Resource
    private PaasCommentModel paasCommentModel;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private PaasAppModel paasAppModel;

    @Override
    public BaseVO add(LikeAddDTO likeAddDTO) throws XbbException {
        Integer businessType = likeAddDTO.getBusinessType();
        BusinessCommentEnum businessCommentEnum = BusinessCommentEnum.getByBusinessType(businessType);
        if (businessCommentEnum == null){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100018);
        }
        // TODO 从移动端详情页里的评论，appId拿不到
        Long appId = likeAddDTO.getAppId();
        String corpid = likeAddDTO.getCorpid();
        Long dataId = likeAddDTO.getDataId();
        PaasFormDataEntityExt paasFormDataEntityExt = saasGetHelp.getFormData(dataId, corpid, likeAddDTO.getBusinessType());
        if (paasFormDataEntityExt == null) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100404, MessageConstant.FORM_DATA_NOT_EXIST);
        }

        PaasFormEntityExt paasFormEntityExt = paasFormModel.getByKey(paasFormDataEntityExt.getFormId(), corpid);
        if (paasFormEntityExt == null) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100404, MessageConstant.FORM_DATA_NOT_EXIST);
        }
        likeAddDTO.setDistributorMark(paasFormEntityExt.getDistributorMark());

        if (appId == 0) {
            appId = paasFormDataEntityExt.getAppId();
            likeAddDTO.setAppId(appId);
        }else{
            PaasAppEntity app = paasAppModel.getByKey(appId, corpid);
            if(Objects.equals(XbbRefTypeEnum.MARKET_MANAGEMENT.getAlias(),app.getAlias()) && Objects.equals(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(),businessType)){
                appId = paasFormDataEntityExt.getAppId();
                likeAddDTO.setAppId(appId);
            }else if(Objects.equals(XbbRefTypeEnum.ORDER_CENTER.getAlias(),app.getAlias()) && Objects.equals(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(),businessType)){
                appId = paasFormDataEntityExt.getAppId();
                likeAddDTO.setAppId(appId);
            }
        }
        Integer type = businessCommentEnum.getCode();
        boolean ifILike = getIfLike(likeAddDTO.getCorpid(),type, appId,likeAddDTO.getDataId(),likeAddDTO.getUserId());
        if (!ifILike){
            UserEntity userEntity = userModel.getByKey(likeAddDTO.getUserId(),likeAddDTO.getCorpid());
            LikeEntity likeEntity = new LikeEntity();
            BeanUtil.copyProperties(likeAddDTO,likeEntity);
            //因为线索的跟进记录是存在客户这边的，所以是线索的在跟进记录这边点赞的话，不能使用线索的appId,这边替换为crm的appId
            if(Objects.equals(XbbRefTypeEnum.CLUE.getCode(),businessType)){
                PaasFormEntityExt customerCommunicateForm = paasFormModel.getByBusinessType(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), corpid);
                if(Objects.nonNull(customerCommunicateForm)){
                    likeEntity.setAppId(customerCommunicateForm.getAppId());
                }
            }
            likeEntity.setRefId(likeAddDTO.getDataId());
            likeEntity.setUserId(userEntity.getUserId());
            likeEntity.setUserName(userEntity.getName());
            likeEntity.setUserAvatar(userEntity.getAvatar());
            likeEntity.setType(type);
            likeModel.save(likeEntity);
            // 点赞消息推送
            pushLike(likeAddDTO.getLoginUser(), businessType, corpid, dataId, paasFormDataEntityExt, likeAddDTO.getDistributorMark());
        } else {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, ErrorMessageConstant.ALREADY_LIKED);
        }
        return new BaseVO();
    }

    @Override
    public BaseVO addLikeOnComment(LikeAddOnCommentDTO likeAddOnCommentDTO) throws XbbException {
        try {
            Integer businessType = likeAddOnCommentDTO.getBusinessType();
            BusinessCommentEnum businessCommentEnum = BusinessCommentEnum.getByBusinessType(businessType);
            if (businessCommentEnum == null){
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100018);
            }
            Long appId = likeAddOnCommentDTO.getAppId();
            String corpid = likeAddOnCommentDTO.getCorpid();
            Long dataId = likeAddOnCommentDTO.getDataId();

            Long id = 0L;
            String creatorId = "";
//            if (Objects.equals(likeAddOnCommentDTO.getFatherComment(), 0)) {
                //点赞的那条评论
                PaasCommentEntity paasCommentEntity = paasCommentModel.getByKey(dataId, corpid);
                if (Objects.isNull(paasCommentEntity)) {
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100018);
                }
                id = paasCommentEntity.getRefId();
                creatorId = paasCommentEntity.getUserId();
//            } else {
//                //点赞的那条评论
//                PaasCommentEntity paasCommentEntity = paasCommentModel.getByKey(dataId, corpid);
//                if (Objects.isNull(paasCommentEntity)) {
//                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100018);
//                }
//                //查找点赞的评论的父级评论
//                PaasCommentEntity commentEntity = paasCommentModel.getByKey(paasCommentEntity.getRefId(), corpid);
//                if (Objects.isNull(commentEntity)) {
//                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100018);
//                }
//                id = commentEntity.getRefId();
//                creatorId = paasCommentEntity.getUserId();
//            }

            PaasFormDataEntityExt paasFormDataEntityExt = saasGetHelp.getFormData(id, corpid, businessType);
            if (Objects.isNull(paasFormDataEntityExt)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100018);
            }

            Integer type = businessCommentEnum.getCode();
            boolean ifILike = getIfLike(likeAddOnCommentDTO.getCorpid(), type, appId, likeAddOnCommentDTO.getDataId(), likeAddOnCommentDTO.getUserId());
            if (!ifILike){
                UserEntity userEntity = userModel.getByKey(likeAddOnCommentDTO.getUserId(), likeAddOnCommentDTO.getCorpid());
                LikeEntity likeEntity = new LikeEntity();
                BeanUtil.copyProperties(likeAddOnCommentDTO, likeEntity);
                likeEntity.setRefId(likeAddOnCommentDTO.getDataId());
                likeEntity.setUserId(userEntity.getUserId());
                likeEntity.setUserName(userEntity.getName());
                likeEntity.setUserAvatar(userEntity.getAvatar());
                likeEntity.setType(type);
                likeModel.save(likeEntity);


                // 点赞消息推送
                String pushTitle = "";
                String pushContent = "";
                PushTypeEnum pushTypeEnum = null;
                switch (businessCommentEnum) {
                    case WORK_ORDER:
                        pushTitle = I18nMessageUtil.getMessage(WorkOrderPushConstant.WORK_ORDER_COMMENT_TITLE);
                        pushContent = String.format(I18nMessageUtil.getMessage(WorkOrderPushConstant.PUSH_LIKE), likeAddOnCommentDTO.getLoginUser().getName(), paasFormDataEntityExt.getSerialNo());
                        pushTypeEnum = PushTypeEnum.WORKORDER_COMMENT_LIKE_PUSH;
                        break;
                    default:
                        break;
                }

                if (Objects.nonNull(pushTypeEnum)) {
                    //推送给创建人
                    List<String> pushUserList = new ArrayList<>();
                    pushUserList.add(creatorId);
                    pushUserList.remove(likeAddOnCommentDTO.getLoginUser().getUserId());
                    if (pushUserList.size() > 0) {
                        PushRefTypePojo.Options  options = new PushRefTypePojo.Options(paasFormDataEntityExt.getAppId(), paasFormDataEntityExt.getMenuId(), paasFormDataEntityExt.getFormId(), id, Collections.singletonList(id), SaasMarkEnum.SAAS.getCode(), businessType, businessType);
                        MessageRabbitMqDTO messageRabbitMqDTO = new MessageRabbitMqDTO(corpid, pushUserList, Collections.singletonList(id), 0, null, pushTitle, pushContent, null, options);
                        baseProducer.sendMessage(pushTypeEnum, messageRabbitMqDTO);
                    }
                }

            } else {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, ErrorMessageConstant.ALREADY_LIKED);
            }

        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return new BaseVO();
    }

    @Override
    public void pushLike(UserVO loginUser, Integer businessType, String corpid, Long dataId, PaasFormDataEntityExt paasFormDataEntityExt, Integer distributorMark) throws XbbException {
        Integer businessType4Distributor = XbbRefTypeEnum.transferBusinessType4Distributor(businessType, distributorMark);
        BusinessCommentEnum businessCommentEnum = BusinessCommentEnum.getByBusinessType(businessType4Distributor);
        if (Objects.isNull(businessCommentEnum)) {
            return;
        }
        String pushTitle = "";
        String pushContent = "";
        PushTypeEnum pushTypeEnum = null;
        switch (businessCommentEnum) {
            case CUSTOMER_COMMUNICATE:
                String customerName = paasFormDataEntityExt.getData().getString(CustomerCommunicateEnum.CUSTOMER_NAME_LINK_TEXT.getAttr());
                pushTitle = I18nMessageUtil.getMessage(CommunicatePushConstant.COMMUNICATE_LIKE_TITLE);
                pushContent = String.format(I18nMessageUtil.getMessage(CommunicatePushConstant.COMMUNICATE_LIKE_CONTENT), loginUser.getName(), customerName);
                Integer isClue = FastJsonHelper.getIntegerOrDefaultFromFormData(paasFormDataEntityExt.getData(), CustomerCommunicateEnum.COMMUNICATE_BUSINESS_TYPE.getAttr(), 0);
                if (Objects.equals(isClue, XbbRefTypeEnum.CLUE.getCode())) {
                    customerName = FastJsonHelper.getStringOrDefaultFromFormData(paasFormDataEntityExt.getData(), CustomerCommunicateEnum.COMMUNICATE_BUSINESS_LINK_TEXT.getAttr(), "");
                    pushContent = String.format(I18nMessageUtil.getMessage(CommunicatePushConstant.COMMUNICATE_LIKE_CONTENT_CLUE), loginUser.getName(),
                            customerName);
                }
                pushTypeEnum = PushTypeEnum.COMMUNICATE_LIKE_PUSH;
                break;
            case WORK_REPORT:
                pushTitle = I18nMessageUtil.getMessage(WorkReportPushConstant.WORK_REPORT_LIKE_TITLE);
                pushContent = String.format(I18nMessageUtil.getMessage(WorkReportPushConstant.WORK_REPORT_LIKE_CONTENT), loginUser.getName());
                pushTypeEnum = PushTypeEnum.WORK_REPORT_COMMENT_LIKE_PUSH;
                break;
            case DISTRIBUTOR_COMMUNICATE:
                String distributorName = paasFormDataEntityExt.getData().getString(DistributorCommunicateEnum.DISTRIBUTOR_NAME_LINK_TEXT.getAttr());
                pushTitle = I18nMessageUtil.getMessage(DistributorCommunicatePushConstant.DISTRIBUTOR_COMMUNICATE_LIKE_TITLE);
                pushContent = String.format(I18nMessageUtil.getMessage(DistributorCommunicatePushConstant.DISTRIBUTOR_COMMUNICATE_LIKE_CONTENT), loginUser.getName(), distributorName);
                pushTypeEnum = PushTypeEnum.DISTRIBUTOR_COMMUNICATE_LIKE_PUSH;
                break;
            default:
                break;
        }
        if (Objects.nonNull(pushTypeEnum)) {
            // 推送给创建人
            if (!Objects.equals(paasFormDataEntityExt.getCreatorId(), loginUser.getUserId())) {
                List<String> pushUserList = Collections.singletonList(paasFormDataEntityExt.getCreatorId());
                PushRefTypePojo.Options  options = new PushRefTypePojo.Options(paasFormDataEntityExt.getAppId(), paasFormDataEntityExt.getMenuId(),
                        paasFormDataEntityExt.getFormId(), dataId, Collections.singletonList(dataId), SaasMarkEnum.SAAS.getCode(), businessType, businessType, distributorMark);
                MessageRabbitMqDTO messageRabbitMqDTO = new MessageRabbitMqDTO(corpid, pushUserList, Collections.singletonList(dataId), 0, null, pushTitle, pushContent, null, options);
                baseProducer.sendMessage(pushTypeEnum, messageRabbitMqDTO);
            }
        }
    }

    @Override
    public Integer getCount(String corpid, Integer type, Long appId, Long dataId, String userId) throws XbbException{
        Map<String,Object> map = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        map.put("corpid",corpid);
        map.put("type",type);
        map.put("appId",appId);
        map.put("refId",dataId);
        map.put("del",0);
        return likeModel.getEntitysCount(map);
    }

    @Override
    public Boolean getIfLike(String corpid, Integer type, Long appId, Long dataId, String userId) throws XbbException{
        Map<String,Object> map = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        map.put("corpid",corpid);
        map.put("type",type);
        map.put("appId",appId);
        map.put("refId",dataId);
        map.put("userId",userId);
        map.put("del",0);
        return likeModel.getEntitysCount(map) > 0;
    }

    @Override
    public LikeListVO list(LikeListDTO likeListDTO) throws XbbException{
        BusinessCommentEnum businessCommentEnum = BusinessCommentEnum.getByBusinessType(likeListDTO.getBusinessType());
        if (businessCommentEnum == null){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100018);
        }
        String corpid = likeListDTO.getCorpid();
        Long dataId = likeListDTO.getDataId();
        Long appId = likeListDTO.getAppId();
        Integer businessType = likeListDTO.getBusinessType();
        PaasFormDataEntityExt paasFormDataEntityExt = saasGetHelp.getFormData(dataId, corpid, likeListDTO.getBusinessType());
        if (paasFormDataEntityExt == null) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_DATA_NOT_EXIST);
        }
        // TODO 从移动端详情页里的评论，appId拿不到
        if (appId == 0) {
            appId = paasFormDataEntityExt.getAppId();
            likeListDTO.setAppId(appId);
        }else {
            PaasAppEntity app = paasAppModel.getByKey(appId, corpid);
            if(Objects.equals(XbbRefTypeEnum.MARKET_MANAGEMENT.getAlias(),app.getAlias()) && Objects.equals(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(),businessType)){
                appId = paasFormDataEntityExt.getAppId();
                likeListDTO.setAppId(appId);
            }else if(Objects.equals(XbbRefTypeEnum.ORDER_CENTER.getAlias(),app.getAlias()) && Objects.equals(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(),businessType)){
                appId = paasFormDataEntityExt.getAppId();
                likeListDTO.setAppId(appId);
            }
        }
        // 线索跟进记录这边appid特殊处理一下
        appId = getAppId4Clue(likeListDTO.getCorpid(), likeListDTO.getBusinessType(), appId);
        String userId = likeListDTO.getUserId();
        String platForm = likeListDTO.getPlatform();
        Integer type = businessCommentEnum.getCode();
        Map<String,Object> map = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        map.put("corpid",likeListDTO.getCorpid());
        map.put("appId",appId);
        map.put("type",type);
        map.put("refId",likeListDTO.getDataId());
        map.put("del",0);
        List<LikeEntity> likeEntityList = likeModel.findEntitys(map);
        JSONArray likeArray = new JSONArray();
        boolean containMe = false;
        String otherUserName = "";
        for (LikeEntity entity : likeEntityList){
            String likeUserId = entity.getUserId();
            if (Objects.equals(userId, likeUserId)) {
                containMe = true;
            } else {
                otherUserName = entity.getUserName();
            }
            JSONObject json = new JSONObject();
            json.put("userId", likeUserId);
            json.put("userName", entity.getUserName());
            json.put("userAvatar", entity.getUserAvatar());
            likeArray.add(json);
        }
        LikeListVO likeListVO = new LikeListVO();
        likeListVO.setLikeArray(likeArray);
        likeListVO.setLikeCount(likeArray.size());
        if (Objects.equals(PlatFormEnum.DINGTALK.getValue(), platForm)) {
            String message = "";
            if (likeArray.size() == 1) {
                if (containMe) {
                    message = String.format(I18nMessageUtil.getMessage(I18nStringConstant.FEEL_LIKE), I18nMessageUtil.getMessage(CommonConstant.ME));
                } else {
                    JSONObject jsonObject = (JSONObject) likeArray.get(0);
                    String userName = jsonObject.getString("userName");
                    message = String.format(I18nMessageUtil.getMessage(I18nStringConstant.FEEL_LIKE), userName);
                }
            } else if (likeArray.size() == 2) {
                if (containMe) {
                    message = String.format(I18nMessageUtil.getMessage(I18nStringConstant.FEEL_LIKE), I18nMessageUtil.getMessage(CommonConstant.WITH_ME) + otherUserName);
                } else {
                    message = String.format(I18nMessageUtil.getMessage(I18nStringConstant.FEEL_LIKE), otherUserName);
                }
            } else if (likeArray.size() > 2) {
                if (containMe) {
                    message = I18nMessageUtil.getMessage(CommonConstant.WITH_ME) + otherUserName;
                } else {
                    message = otherUserName;
                }
                message = message + I18nMessageUtil.getMessage(CommonConstant.ETC) + String.format(I18nMessageUtil.getMessage(I18nStringConstant.FEEL_LIKE), likeArray.size());
            }
            if (StringUtil.isNotEmpty(message)) {
                likeListVO.setMessage(message);
            }

//            StringBuffer message = new StringBuffer();
//            if (likeArray.size() == 1) {
//                if (containMe) {
//                    message = message.append("我觉得很赞");
//                } else {
//                    JSONObject jsonObject = (JSONObject) likeArray.get(0);
//                    String userName = jsonObject.getString("userName");
//                    message = message.append(userName).append("觉得很赞");
//                }
//            } else if (likeArray.size() == 2) {
//                if (containMe) {
//                    message = message.append("我和").append(otherUserName).append("觉得很赞");
//                } else {
//                    message = message.append(otherUserName).append("觉得很赞");
//                }
//            } else if (likeArray.size() > 2) {
//                if (containMe) {
//                    message = message.append("我和").append(otherUserName);
//                } else {
//                    message = message.append(otherUserName);
//                }
//                message = message.append("等").append(likeArray.size()).append("觉得很赞");
//            }
//            if (message.length() > 0) {
//                likeListVO.setMessage(message.toString());
//            }
        }
        return likeListVO;
    }

    @Override
    public Map<Long, Integer> getLikeCountMap(List<Long> dataIdIn, String corpid, Integer code) {
        return likeModel.getLikeCountMap(dataIdIn, corpid, code);
    }

    @Override
    public List<Long> hasMyLike(List<Long> dataIdIn, String corpid, Integer type, String userId) {
        return likeModel.hasMyLike(dataIdIn, corpid, type, userId);
    }

    /**
     * 线索跟进记录这边，拿的是客户的跟进记录，用客户跟进记录的业务的appid都和客户跟进记录一样，所以不用转，
     * 但是线索详情页的跟进记录这边，获取点赞或者评论拿的都是市场管理的appid，对不上了
     * 结果，这边特殊处理一下，如果是线索的跟进记录这边，拿的就是客户跟进记录的appid，其它的按原来的处理
     * @param corpid
     * @param businessType
     * @param appId
     * @return
     */
    private Long getAppId4Clue(String corpid, Integer businessType, Long appId){
        if(Objects.equals(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(),businessType) && Objects.nonNull(appId) && appId > 0){
            PaasAppEntity app = paasAppModel.getByKey(appId, corpid);
            if(Objects.nonNull(app) && XbbRefTypeEnum.MARKET_MANAGEMENT.getAlias().equals(app.getAlias())){
                PaasFormEntityExt customerCommunicateForm = paasFormModel.getByBusinessType(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), corpid);
                if(Objects.nonNull(customerCommunicateForm)){
                    return  customerCommunicateForm.getAppId();
                }
            }
        }
        return appId;
    }
}
